﻿using Caliburn.Micro;
using MusicExplorer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml.Media.Imaging;
using MusicExplorer.Extensions;
using MusicExplorer.Tools;
using Windows.UI.Core;

namespace MusicExplorer.ViewModels.Wrappers
{
    public sealed class RepositoryTileViewModel : PropertyChangedBase
    {
        private readonly Model.Repository m_repository;
        private readonly PageViewModelBase m_parent;

        private RepositoryTileViewModel(PageViewModelBase parent, Model.Repository repository)
        {
            m_repository = repository;
            m_parent = parent;
        }

        public static async Task<RepositoryTileViewModel> CreateAsync(PageViewModelBase parent, Model.Repository repository)
        {
            var wrapper = new RepositoryTileViewModel(parent, repository);
            await wrapper.InitializeAsync();
            return wrapper;
        }

        public async Task InitializeAsync()
        {
            m_image = new BitmapImage();
            await m_image.FillWithImageRepositoryAsync(m_repository);
            NotifyOfPropertyChange(() => Image);
        }

        public Model.Repository Repository { get { return m_repository; } }
        public PageViewModelBase Parent { get {return m_parent; } }
        public string DisplayName { get { return m_repository.Name; } }

        private BitmapImage m_image;
        public BitmapImage Image { get { return m_image; } }


    }
}
